package com.tianpengtech.front.mobile.publisher;

import com.jfinal.kit.StrKit;
import com.tianpengtech.admin.dictionary.DictionaryDao;
import com.tianpengtech.common.model.user.User;
import com.tianpengtech.front.mobile.common.util.R;
import com.tianpengtech.front.mobile.common.util.UserUtil;
import com.tianpengtech.front.web.common.controller.BaseController;

/**
 * Created by ggd on 2017/8/3 0003.
 */
public class MobilePublishController extends BaseController {

    private static MobilePublishService service = MobilePublishService.me;
    private DictionaryDao dictionaryDao = new DictionaryDao();
    /**
     * 获取商家信息
     */
    public void getPublish(){
        String id=getPara("id");
        if (StrKit.isBlank(id)){
            renderJson(R.fail("id不能为空"));
            return;
        }
        R r=service.getPublish(id);
        renderJson(r);
    }


    /**
     * 获取商家任务信息
     */
    public void getPublishTask(){
        String id=getPara("id");
        if (StrKit.isBlank(id)){
            renderJson(R.fail("id不能为空"));
            return;
        }
        int pageNum = getParaToInt("pageNum",1);
        int pageSize = getParaToInt("pageSize",5);
        R r=service.getPublishTask(pageNum,pageSize,id);
        renderJson(r);
    }


    /**
     * 获取商家评论信息
     */
    public void getPublishComment(){
        String id=getPara("id");
        if (StrKit.isBlank(id)){
            renderJson(R.fail("id不能为空"));
            return;
        }
        int pageNum = getParaToInt("pageNum",1);
        int pageSize = getParaToInt("pageSize",5);
        R r=service.getPublishComment(pageNum,pageSize,id);
        renderJson(r);
    }

    /**
     * 获取举报信息
     */
    public void getReportInfo(){
        R r = R.ok();
        r.p("reports",dictionaryDao.readParents(200100));
        renderJson(r);
    }

    /**
     * 保存举报信息
     */
    public void saveReport(){
        String content = getPara("content");
        String contentId = getPara("contentId");
        String userId = getPara("userId");
        User user= UserUtil.getCurrentUser(getPara("token"),getHeader("source"));
        long uid=user.getLong(User.ID);
        if (StrKit.isBlank(content) && StrKit.isBlank(contentId)){
            renderJson(R.fail("请输入举报原因"));
            return;
        }
        if (StrKit.isBlank(userId)){
            renderJson(R.fail("请输入被举报人信息"));
            return;
        }
        R r=service.saveReport(contentId,content,uid,userId);
        renderJson(r);
    }



}
